home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Develop.lha / xpk_Develop / Include / Oberon / XpkMaster.mod next >
Text File  |  1998-11-09  |  16KB  |  394 lines

  1. (*************************************************************************
  2.  
  3. :Program.    XpkMaster.mod
  4. :Contents.   Interface-Module for xpkmaster.library
  5. :Author.     Hartmut Goebel [hG]
  6. :Copyright.  Copyright © 1991 by Hartmut Goebel
  7. :Copyright.  May be free dirstibuted with the Xpk-Package
  8. :Copyright.  permission is given to be inlcuded with AmigaOberon
  9. :Language.   Oberon
  10. :Translator. Amiga Oberon V2.14
  11. :History.    V0.9, 08 Jan 1992 Hartmut Goebel [hG]
  12. :History.    V1.0, 04 Jun 1992 [hG]
  13. :History.    V1.1, 06 Jul 1992 [hG] remove "Xpk" from procname, because
  14. :History.          in Oberon you U must import qualified, so this is useless
  15. :History.    V1.1b 27 Jul 1992 [hG] XpkMasterNA build in
  16. :History.    V2.0  04 Aug 1992 [hG] adapted to Xpk 2.0
  17. :Date.       04 Aug 1992 01:25:20
  18.  
  19. :Remark.     compile with "set NoAssert" to generate XpkMasterNA, which
  20. :Remark.     does not asure the lib is opened successfull (you must check
  21. :Remark.     this by yourself then!)
  22.  
  23. *************************************************************************)
  24.  
  25. (* $IFNOT NoAssert *)
  26.  
  27. MODULE XpkMaster;
  28.  
  29. (* $ELSE *)
  30.  
  31. MODULE XpkMasterNA;
  32.  
  33. (* $END *)
  34.  
  35. IMPORT
  36.   e * := Exec,
  37.   I * := Intuition,
  38.   s * := SYSTEM,
  39.   u * := Utility;
  40.  
  41. CONST
  42.  
  43.   XpkName = "xpkmaster.library";
  44.  
  45. (*****************************************************************************
  46.  *
  47.  *
  48.  *      The packing/unpacking tags
  49.  *
  50.  *)
  51.  
  52. (* Tags we support *)
  53.   tagBase       * = u.user + ORD("X")*256 + ORD("P");
  54.  
  55. (* Caller must supply ONE of these to tell Xpk#?ackFile where to get data from *)
  56.   inName        * = tagBase+01H; (* Process an entire named file *)
  57.   inFH          * = tagBase+02H; (* File handle - start from current position *)
  58.                                  (* If packing partial file, must also supply InLen *)
  59.   inBuf         * = tagBase+03H; (* Single unblocked memory buffer *)
  60.                                  (* Must also supply InLen *)
  61.   inHook        * = tagBase+04H; (* Call custom Hook to read data *)
  62.                                  (* If packing, must also supply InLen *)
  63.                                  (* If unpacking, InLen required only for PPDecrunch *)
  64.  
  65. (* Caller must supply ONE of these to tell Xpk#?ackFile where to send data to *)
  66.   outName       * = tagBase+10H; (* Write (or overwrite) this data file *)
  67.   outFH         * = tagBase+11H; (* File handle - write from current position on *)
  68.   outBuf        * = tagBase+12H; (* Unblocked buffer - must also supply OutBufLen *)
  69.   getOutBuf     * = tagBase+13H; (* Master allocates OutBuf - ti_Data points to buf ptr *)
  70.   outHook       * = tagBase+14H; (* Callback Hook to get output buffers *)
  71.  
  72. (* Other tags for Pack/Unpack *)
  73.   inLen         * = tagBase+20H; (* Length of data in input buffer *)
  74.   outBufLen     * = tagBase+21H; (* Length of output buffer *)
  75.   getOutLen     * = tagBase+22H; (* ti_Data points to long to receive OutLen *)
  76.   getOutBufLen  * = tagBase+23H; (* ti_Data points to long to receive OutBufLen *)
  77.   password      * = tagBase+24H; (* Password for de/encoding *)
  78.   getError      * = tagBase+25H; (* ti_Data points to buffer for error message *)
  79.   outMemType    * = tagBase+26H; (* Memory type for output buffer *)
  80.   passThru      * = tagBase+27H; (* Bool: Pass through unrecognized formats on unpack *)
  81.   stepDown      * = tagBase+28H; (* Bool: Step down pack method if necessary *)
  82.   chunkHook     * = tagBase+29H; (* Call this Hook between chunks *)
  83.   packMethod    * = tagBase+2AH; (* Do a FindMethod before packing *)
  84.   chunkSize     * = tagBase+2BH; (* Chunk size to try to pack with *)
  85.   packMode      * = tagBase+2CH; (* Packing mode for sublib to use *)
  86.   noClobber     * = tagBase+2DH; (* Don't overwrite existing files  *)
  87.   ignore        * = tagBase+2EH; (* Skip this tag                   *)
  88.   taskPri       * = tagBase+2FH; (* Change priority for (un)packing *)
  89.   fileName      * = tagBase+30H; (* File name for progress report   *)
  90.   shortError    * = tagBase+31H; (* Output short error messages     *)
  91.   packersQuery  * = tagBase+32H; (* Query available packers         *)
  92.   packerQuery   * = tagBase+33H; (* Query properties of a packer    *)
  93.   modeQuery     * = tagBase+34H; (* Query properties of packmode    *)
  94.   lossyOK       * = tagBase+35H; (* Lossy packing permitted? def.=no*)
  95.  
  96.   findMethod    * = packMethod;  (* Compatibility *)
  97.  
  98.   margin        * = 256;         (* Safety margin for output buffer      *)
  99.  
  100.  
  101. TYPE
  102. (*****************************************************************************
  103.  *
  104.  *
  105.  *     The hook function interface
  106.  *
  107.  *)
  108.  
  109. (* Message passed to InHook and OutHook as the ParamPacket *)
  110.   XpkIOMsgPtr * = POINTER TO XpkIOMsg;
  111.   XpkIOMsg * = STRUCT
  112.     type     * : LONGINT;   (* Read/Write/Alloc/Free/Abort        *)
  113.     ptr      * : e.APTR;    (* The mem area to read from/write to *)
  114.     size     * : LONGINT;   (* The size of the read/write         *)
  115.     ioError  * : LONGINT;   (* The IoErr() that occurred          *)
  116.     reserved * : e.ADDRESS; (* Reserved for future use            *)
  117.     private1 * : e.ADDRESS; (* Hook specific, will be set to 0 by *)
  118.     private2 * : e.ADDRESS; (* master library before first use    *)
  119.     private3 * : e.ADDRESS;
  120.     private4 * : e.ADDRESS;
  121.   END;
  122.  
  123. CONST
  124. (* The values for XpkIoMsg.type *)
  125.   ioRead    * = 1;
  126.   ioWrite   * = 2;
  127.   ioFree    * = 3;
  128.   ioAbort   * = 4;
  129.   ioGetBuf  * = 5;
  130.   ioSeek    * = 6;
  131.   ioTotSize * = 7;
  132.  
  133.  
  134. (*****************************************************************************
  135.  *
  136.  *
  137.  *      The progress report interface
  138.  *
  139.  *)
  140.  
  141. TYPE
  142. (* Passed to ChunkHook as the ParamPacket *)
  143.   XpkProgressPtr * = POINTER TO XpkProgress;
  144.   XpkProgress * = STRUCT
  145.     type           * : LONGINT;  (* Type of report: start/cont/end/abort       *)
  146.     packerName     * : e.STRPTR; (* Brief name of packer being used            *)
  147.     packerLongName * : e.STRPTR; (* Descriptive name of packer being used      *)
  148.     activity * : e.STRPTR;       (* Packing/unpacking message                  *)
  149.     fileName * : e.STRPTR;       (* Name of file being processed, if available *)
  150.     cCur  * : LONGINT;           (* Amount of packed data already processed    *)
  151.     uCur  * : LONGINT;           (* Amount of unpacked data already processed  *)
  152.     uLen  * : LONGINT;           (* Amount of unpacked data already processed  *)
  153.     cf    * : LONGINT;           (* Compression factor so far                  *)
  154.     done  * : LONGINT;           (* Percentage done already                    *)
  155.     speed * : LONGINT;           (* Bytes per second, from beginning of stream *)
  156.     reserved * : ARRAY 8 OF e.ADDRESS; (* For future use               *)
  157.   END;
  158.  
  159. CONST
  160. (* The values for XpkProgress.type *)
  161.   progStart * = 1;
  162.   progMid   * = 2;
  163.   progEnd   * = 3;
  164.  
  165. (*****************************************************************************
  166.  *
  167.  *
  168.  *       The file info block
  169.  *
  170.  *)
  171.  
  172. TYPE
  173.   XpkFibPtr * = POINTER TO XpkFib;
  174.   XpkFib * = STRUCT
  175.     type * : LONGINT                 ; (* Unpacked, packed, archive?   *)
  176.     uLen * : LONGINT                 ; (* Uncompressed length          *)
  177.     cLen * : LONGINT                 ; (* Compressed length            *)
  178.     nLen * : LONGINT                 ; (* Next chunk len               *)
  179.     uCur * : LONGINT                 ; (* Uncompressed bytes so far    *)
  180.     cCur * : LONGINT                 ; (* Compressed bytes so far      *)
  181.     id     * : ARRAY 4 OF BYTE       ; (* 4 letter ID of packer        *)
  182.     packer * : ARRAY 6 OF BYTE       ; (* 4 letter name of packer      *)
  183.     subVersion * : INTEGER           ; (* Required sublib version      *)
  184.     masVersion * : INTEGER           ; (* Required masterlib version   *)
  185.     flags * : LONGSET                ; (* Password?                    *)
  186.     head * : ARRAY 16 OF BYTE        ; (* First 16 bytes of orig. file *)
  187.     ratio * : LONGINT                ; (* Compression ratio            *)
  188.     reserved * : ARRAY 8 OF e.ADDRESS; (* For future use               *)
  189.   END;
  190.  
  191.   XpkFH * = POINTER TO STRUCT
  192.     fib*: XpkFib
  193.     (* private data follows *)
  194.   END;
  195.  
  196. CONST
  197. (* Defines for XpkFib.type *)
  198.   typeUnpacked * = 0;        (* Not packed                   *)
  199.   typePacked   * = 1;        (* Packed file                  *)
  200.   typeArchive  * = 2;        (* Archive                      *)
  201.  
  202. (* Defines for XpkFib.flags *)
  203.   flagsPassword * = 0;       (* Password needed              *)
  204.   flagsNoSeek   * = 1;       (* Chunks are dependent         *)
  205.   flagsNonStd   * = 2;       (* Nonstandard file format      *)
  206.  
  207.  
  208. CONST
  209. (*****************************************************************************
  210.  *
  211.  *
  212.  *       The error messages
  213.  *
  214.  *)
  215.  
  216.   errOk         * =  0;
  217.   errNoFunc     * = -1;   (* This function not implemented         *)
  218.   errNoFiles    * = -2;   (* No files allowed for this function    *)
  219.   errIOErrIn    * = -3;   (* Input error happened, look at Result2 *)
  220.   errIOErrOut   * = -4;   (* Output error happened,look at Result2 *)
  221.   errCheckSum   * = -5;   (* Check sum test failed                 *)
  222.   errVersion    * = -6;   (* Packed file's version newer than lib  *)
  223.   errNoMem      * = -7;   (* Out of memory                         *)
  224.   errLibInUse   * = -8;   (* For not-reentrant libraries           *)
  225.   errWrongForm  * = -9;   (* Was not packed with this library      *)
  226.   errSmallBuf   * = -10;  (* Output buffer too small               *)
  227.   errLargeBuf   * = -11;  (* Input buffer too large                *)
  228.   errWrongMode  * = -12;  (* This packing mode not supported       *)
  229.   errNeedPasswd * = -13;  (* Password needed for decoding          *)
  230.   errCorruptPkd * = -14;  (* Packed file is corrupt                *)
  231.   errMissingLib * = -15;  (* Required library is missing           *)
  232.   errBadParams  * = -16;  (* Caller's TagList was screwed up       *)
  233.   errExpansion  * = -17;  (* Would have caused data expansion      *)
  234.   errNoMethod   * = -18;  (* Can't find requested method           *)
  235.   errAborted    * = -19;  (* Operation aborted by user             *)
  236.   errTruncated  * = -20;  (* Input file is truncated               *)
  237.   errWrongCPU   * = -21;  (* Better CPU required for this library  *)
  238.   errPacked     * = -22;  (* Data are already XPacked              *)
  239.   errNotPacked  * = -23;  (* Data not packed                       *)
  240.   errFileExists * = -24;  (* File already exists                   *)
  241.   errOldMastLib * = -25;  (* Master library too old                *)
  242.   errOldSubLib  * = -26;  (* Sub library too old                   *)
  243.   errNoCrypt    * = -27;  (* Cannot encrypt                        *)
  244.   errNoInfo     * = -28;  (* Can't get info on that packer         *)
  245.   errLossy      * = -29;  (* This compression method is lossy      *)
  246.   errNoHardware * = -30;  (* Compression hardware required         *)
  247.   errBadHardware* = -31;  (* Compression hardware failed           *)
  248.   errWrongPW    * = -32;  (* Password was wrong                    *)
  249.  
  250.   errMsgSize    * =  80;  (* Maximum size of an error message      *)
  251.  
  252. (*****************************************************************************
  253.  *
  254.  *
  255.  *     The XpkQuery() call
  256.  *
  257.  *)
  258.  
  259. TYPE
  260.   XpkPackerInfoPtr * = POINTER TO XpkPackerInfo;
  261.   XpkPackerInfo * = STRUCT
  262.     name * : ARRAY 24 OF CHAR;        (* Brief name of the packer          *)
  263.     longName * : ARRAY 32 OF CHAR;    (* Full name of the packer           *)
  264.     description * : ARRAY 80 OF CHAR; (* One line description of packer    *)
  265.     flags    * : LONGSET;             (* Defined below                     *)
  266.     maxChunk * : LONGINT;             (* Max input chunk size for packing  *)
  267.     defChunk * : LONGINT;             (* Default packing chunk size        *)
  268.     defMode  * : INTEGER;             (* Default mode on 0..100 scale      *)
  269.   END;
  270.  
  271. CONST
  272.   (* Defines for XpkPackerInfo.Flags *)
  273.   pkChunk    * = 0;   (* Library supplies chunk packing       *)
  274.   pkStream   * = 1;   (* Library supplies stream packing      *)
  275.   pkArchive  * = 2;   (* Library supplies archive packing     *)
  276.   upChunk    * = 3;   (* Library supplies chunk unpacking     *)
  277.   upStream   * = 4;   (* Library supplies stream unpacking    *)
  278.   upArchive  * = 5;   (* Library supplies archive unpacking   *)
  279.   hookIO     * = 7;   (* Uses full Hook I/O                   *)
  280.   checking   * = 10;  (* Does its own data checking           *)
  281.   preReadHdr * = 11;  (* Unpacker pre-reads the next chunkhdr *)
  282.   encryption * = 13;  (* Sub library supports encryption      *)
  283.   needPasswd * = 14;  (* Sub library requires encryption      *)
  284.   modes      * = 15;  (* Sub library has different modes      *)
  285.   lossy      * = 16;  (* Sub library does lossy compression   *)
  286.  
  287. TYPE
  288.   XpkModePtr * = POINTER TO XpkMode;
  289.   XpkMode * = STRUCT
  290.     next * : XpkModePtr;      (* Chain to next descriptor for ModeDesc list*)
  291.     upto * : LONGINT;         (* Maximum efficiency handled by this mode   *)
  292.     flags * : LONGSET;        (* Defined below                             *)
  293.     packMemory   * : LONGINT; (* Extra memory required during packing      *)
  294.     unpackMemory * : LONGINT; (* Extra memory during unpacking             *)
  295.     packSpeed    * : LONGINT; (* Approx packing speed in K per second      *)
  296.     unpackSpeed  * : LONGINT; (* Approx unpacking speed in K per second    *)
  297.     ratio    * : INTEGER;     (* CF in 0.1%                                *)
  298.     chunkSize * : INTEGER;    (* Desired chunk size in K (!!) for this mode*)
  299.     description * : ARRAY 10 OF CHAR; (* 7 character mode description      *)
  300.   END;
  301.  
  302. (* Defines for XpkMode.Flags *)
  303. CONST
  304.   mfA3000Speed * = 0;     (* Timings on A3000/25               *)
  305.   mfPkNoCPU    * = 1;     (* Packing not heavily CPU dependent *)
  306.   mfUpNoCPU    * = 2;     (* Unpacking... (i.e. hardware modes)*)
  307.  
  308. CONST
  309.   maxPackers * = 100;
  310.  
  311. TYPE
  312.   XpkPackerListPtr = POINTER TO XpkPackerList;
  313.   XpkPackerList = STRUCT
  314.     numPackers: LONGINT;
  315.     Packer: ARRAY maxPackers,6 OF BYTE;
  316.   END;
  317.  
  318. (*****************************************************************************
  319.  *
  320.  *
  321.  *     The XpkOpen() type calls
  322.  *
  323.  *)
  324.  
  325. CONST
  326.   lenOneChunk * = 7FFFFFFFH;
  327.  
  328.  
  329. (*****************************************************************************
  330.  *
  331.  *
  332.  *      The library vectors
  333.  *
  334.  *)
  335.  
  336. VAR
  337.   base * : e.LibraryPtr;
  338.  
  339. (**
  340.  ** Remember: when compiled witch 'SET NoAssert' you must check
  341.  ** if base#NIL before using one of the following functions
  342.  **)
  343.  
  344. PROCEDURE Examine * {base,-36}(VAR fib{8}: XpkFib;
  345.                                tagList{9}: ARRAY OF u.TagItem): LONGINT;
  346. PROCEDURE Pack    * {base,-42}(tagList{8}: ARRAY OF u.TagItem): LONGINT;
  347. PROCEDURE Unpack  * {base,-48}(tagList{8}: ARRAY OF u.TagItem): LONGINT;
  348. PROCEDURE Open    * {base,-54}(VAR xfh{8}: XpkFH;
  349.                                tagList{9}: ARRAY OF u.TagItem): LONGINT;
  350. PROCEDURE Read    * {base,-60}(xfh{8}: XpkFH;
  351.                                buf{9}: ARRAY OF BYTE;
  352.                                len{0}: LONGINT): LONGINT;
  353. PROCEDURE Write   * {base,-66}(xfh{8}: XpkFH;
  354.                                buf{9}: ARRAY OF BYTE;
  355.                                ulen{0}:LONGINT): LONGINT;
  356. PROCEDURE Seek    * {base,-72}(xfh{8}: XpkFH;
  357.                                dist{0}: LONGINT;
  358.                                mode{1}: LONGINT): LONGINT;
  359. PROCEDURE Close   * {base,-78}(xfh{8}: XpkFH): LONGINT;
  360. PROCEDURE Query   * {base,-84}(tagList{8}: ARRAY OF u.TagItem): LONGINT;
  361.  
  362. PROCEDURE ExamineTags * {base,-36}(VAR fib{8}: XpkFib; tag1{9}..: u.Tag): LONGINT;
  363. PROCEDURE PackTags    * {base,-42}(tag1{8}..: u.Tag): LONGINT;
  364. PROCEDURE UnpackTags  * {base,-48}(tag1{8}..: u.Tag): LONGINT;
  365. PROCEDURE OpenTags    * {base,-54}(VAR xfh{8}: XpkFH; tag1{9}..: u.Tag): LONGINT;
  366. PROCEDURE QueryTags   * {base,-84}(tag1{8}..: u.Tag): LONGINT;
  367.  
  368. (* $OvflChk- $RangeChk- $StackChk- $NilChk- $ReturnChk- $CaseChk- *)
  369.  
  370. BEGIN
  371.   base := e.OpenLibrary(XpkName,1);
  372.  
  373. (* $IFNOT NoAssert *)
  374.   IF base=NIL THEN
  375.     s.SETREG(0,
  376.        I.DisplayAlert(0,"\x00\x64\x14missing xpkmaster.library!\o\o",50));
  377.     HALT(0)
  378.   END;
  379. (* $END *)
  380.  
  381. CLOSE
  382.   IF base#NIL THEN e.CloseLibrary(base) END;
  383.  
  384. (* $IFNOT NoAssert *)
  385.  
  386. END XpkMaster.
  387.  
  388. (* $ELSE *)
  389.  
  390. END XpkMasterNA.
  391.  
  392. (* $END *)
  393.  
  394.